/**********************************************
/ file : constellation_mapping.sc
/ Author : Jungmin Park
/ Date : 4/19/2011 
/ Specification Model of Constellation mapping 
***********************************************/
#include <stdio.h>
import "c_double_handshake";

behavior Constellation_mapping (i_receiver ir, i_sender is)
{
  long mask = 0x0000000F;
  long temp = 0;
  unsigned long input1 = 0;
  unsigned long input2 = 0;
  int i;
  float v1, v2;

  void main (void)
  {
   while(1) {
     // Receive the input data
     ir.receive(&input1, sizeof(unsigned long));
     ir.receive(&input2, sizeof(unsigned long));

     for (i=0; i<16; i++) 
     {   
       if ( i >= 8) 
         temp = input2 & mask;
       else 
         temp = input1 & mask;
       switch( temp ) 
       {
         case 0:
           v1 = 1;  
           v2 = 1; 
           break; 
         case 1:
           v1 = 1;
           v2 = 3;
           break;
         case 2:
           v1 = 3;  
           v2 = 1; 
           break; 
         case 3:
           v1 = 3;
           v2 = 3;
           break; 
         case 4:
           v1 = 1;  
           v2 = -1; 
           break; 
         case 5:
           v1 = 1;
           v2 = -3;
           break;
         case 6:
           v1 = 3;  
           v2 = -1; 
           break; 
         case 7:
           v1 = 3;
           v2 = -3;
           break; 
         case 8:
           v1 = -1;  
           v2 = 1; 
           break; 
         case 9:
           v1 = -1;
           v2 = 3;
           break;
         case 10:
           v1 = -3;  
           v2 = 1; 
           break; 
         case 11:
           v1 = -3;
           v2 = 3;
           break; 
         case 12:
           v1 = -1;  
           v2 = -1; 
           break; 
         case 13:
           v1 = -1;
           v2 = -3;
           break;
         case 14:
           v1 = -3;  
           v2 = -1; 
           break; 
         case 15:
           v1 = -3;
           v2 = -3;
           break; 
        }

        is.send(&v1, sizeof(float));
        is.send(&v2, sizeof(float));

        if ( i >= 8) 
          input2 >>= 4;
        else 
          input1 >>= 4;
      
      } // for
    } // while
  } // main
};
